pltmap.m
|
|
The purpose of this function is to demonstrate the use of the
image pseudo object as well as to demonstrate 2D interpolation and 2D convolution.
The subplot parameter is used to partition the figure into two parts. The left part displays a conventional
2D plot which includes the following five traces.
- A circle (red trace) whose radius is controlled by its amplitude slider
(the leftmost slider above the plot in the "Y amplitudes" section).
- A hyperbola (orange trace). Its amplitude slider controls the asymptote slope.
- A polygon (yellow trace). Its amplitude slider controls both the size of the figure
and the number of sides (which range from 3 to 7).
- A line (green trace). Its amplitude slider controls both the line's position and
its orientation. The line is horizontal for slider values less than 5 and vertical otherwise.
- A line (blue trace). Its position and orientation are controlled by its slider in the same
manner as trace 4.
To better understand how the Y amplitude sliders affect the shapes, sizes, and positions of these 5 elements of the left hand plot, first
stop the display from moving by clicking on the stop button. Then make adjustments to the five Y amplitude sliders while observing the
changes in the left plot.
One method used to create the image on the right axis is to use 2D convolution.
This process is controlled by 3 controls to the left of the image (the kernel popup, the kernel size slider,
and the kernel scale slider). This is what the kernel popup looks like once the popup is opened.
First, we start with a completely black image by setting the z matrix to zero and choosing a modified version
of the jet colormap which has had the first color element changed to [0 0 0]. Then we essentially make a copy of what's on the left axis
onto the right axis image by changing one pixel of the image for each of the 500 markers on the left axis (100 markers for each of
the 5 traces). The z values for these 500 points of the image are chosen using the
appropriate index into the jet colormap so that their colors match the colors that appear on the left axis. (Direct
scaling is used since otherwise the colors could not be made to match.) You can see what the image looks like after
this first step by moving the kernel scaling slider down to its smallest setting.
Next, the energy of these 500 points is spread out to affect the neighboring pixels (although the original 500 points
are not changed). This is done by using one of these convolution kernels:
uniform
|
| The uniform kernel is a commonly used "blur" effect where every kernel element is a one. So for example,
this would be the kernel when the kernel size slider is set to 3.
|
| conv11
|
1
| 4
| 6
| 4
| 1
4
| 16
| 24
| 16
| 4
6
| 24
| 36
| 24
| 6
4
| 16
| 24
| 16
| 4
1
| 4
| 6
| 4
| 1
| | | | |
| For a 1D smoother we can convolve the data with [1 1], sometimes called a [1 1] filter which
can be represented as H(z) = 1 + z-1 (i.e. a single zero at z = -1). For more
smoothing we could put two zeros at z = -1 which is the [1 2 1] filter (i.e. [1 1] convolved with
[1 1]). Yet another zero at the same place gives us the [1 3 3 1] filter, and one more to
yield [1 4 6 4 1] (the 4th row of Pascal's triangle if we start counting at 0).
The moral equivalent of this for 2D filtering would be to start with [1] and then convolve with ones(2,2) five times
(assuming the size slider is set to 5). This would yield the convolution kernel shown here. Notice that the 4th row
of Pascal's triangle appears along each of the four edges.
|
| pascal
|
1 | 1 | 1 | 1 | 1
1 | 4 | 4 | 4 | 1
1 | 4 | 6 | 4 | 1
1 | 4 | 4 | 4 | 1
1 | 1 | 1 | 1 | 1
| | | | |
| Another way to extend the 1D [1 4 6 4 1] filter to 2 dimensions would be to place that row in both
the center column and center row as well as along both diagonals.
|
| reverse
|
6 | 6 | 6 | 6 | 6
6 | 4 | 4 | 4 | 6
6 | 4 | 1 | 4 | 6
6 | 4 | 4 | 4 | 6
6 | 6 | 6 | 6 | 6
| | | | |
| This kernel is essentially the reverse of the previous one, with the largest values on the outside instead of the inside.
|
| edge
|
1 | 1 | 1 | 1 | 1
1 | 0 | 0 | 0 | 1
1 | 0 | 0 | 0 | 1
1 | 0 | 0 | 0 | 1
1 | 1 | 1 | 1 | 1
| | | | |
| This kernel has ones along all four edges and zeros elsewhere. This kernel and the previous one (reverse)
have little to no practical applications and are included here just for the cool visual effects.
|
| | All the kernels described above are scaled by an amount related to the scaling slider (the slider right below
the slider that controls the kernel size). If you move the scaling slider to the bottom (minimum value) the
effect of the convolution will be barely noticeable (or unnoticeable). As you move the scaling slider up the
effects of the convolution become more noticeable and dramatic.
| nearest
| Even though this selection (as well as the following one) is in the kernel popup menu, it does not represent
a convolution kernel. Instead, it refers to another method of creating the image known as
nearest neighbor interpolation. The kernel size has no meaning here, but we use the kernel
size slider to control one aspect of this interpolation. Let's start with the simpler case by setting the kernel
size slider to its minimum value (1). The first step is similar to the first step for the convolution methods,
i.e. 500 points are set that align with the same colors used for the 500 markers in the left hand plot. Again
direct scaling is used for the image to allow these colors to match up. Next, each of the remaining points of
the image is set to the color of the point that is nearest. So in the end, every point in the image is set to
one of the 5 colors in use. This type of interpolation produces a continuous but steppy 3D surface (clearly not
differentiable). Matlab's built-in griddata function can be used to perform this interpolation but to better
expose the method, this interpolation is performed by the nearest function included
inside pltmap.m. (This function consists of just a few lines of code.)
| cubic
| While the nearest neighbor interpolation results in an image with sharp color changes, the cubic interpolation
produces a smooth (differentiable) 3D surface, so the colro changes are gradual. Start again with the kernel size
slider set to 1 so the colors of the image match up with the colors of the markers of the left plot, again making it
easier to see how the two plots are related. Next change the kernel size slider to any number bigger than 1. This
causes several changes in the way the image is created. For one, instead of using fixed z values at the marker
positions that relate to the color of the markers, the z value is taken from one of the five z value sliders
(one slider for each of the 5 traces). Since these z values sliders move up and down randomly after the run button
is clicked, a truly mesmerizing image is created with patterns that seem to never repeat. (Since all the Y and Z axis
sliders are controlled by pseudo random sequences, the pattern will of course repeat eventually, but certainly not
in your lifetime.) Secondly, the image scaling is changed from direct to scaled and also the z axis limits (clim)
are adjusted to show only the 68% of the data in the middle of the range (i.e. μ ± &sigma). This results in
a more vibrant display. With all these changes it is difficult to see how the image relates to the marker positions
of the left plot, but you may be so hypnotized that you don't notice this. cubic is the default setting for this
popup and so this will likely be the only mode seen by the casual user of the pltmap program.
|
Try exploring the features of pltmap by running through these tasks, both while the display is running and while it is stopped:
- Disable and enable the various traces by clicking on the trace names in the TraceID box.
Note that the intensity map shape is determined only from the enabled traces. There is one exception to that rule
that occurs when just a single line (trace 4 or 5) is enabled. In that situation, griddata won't have enough data
to interpolate the image, so the data for trace 1 will also be used even if it has been disabled on the left hand plot.
- Select the nearest neighbor interpolation and enable the use of the Z amplitude sfliders by selecting a kernel size bigger than
one. Then adjust the "Z amplitudes" for each of the 5 traces using the sliders and notice how these sliders change the image.
(Only the right plot is affected.) You can also do this with the cubic interpolation.
- Click on the "color bar", the vertical color key strip near the upper left corner of
the intensity map. Note that this cycles the color map through 11 choices (The 10 default
color maps and one additional one called jetB added by pltmap. Often which color map to
use is simply a visual preference, but for this program, the jetB color map is best so that
the colors can match up between the left and right plots (at least when the Z amplitude
sliders are not being used.)
- Note that the intensity map appears somewhat pixelated. This is because it is composed
of a relatively small number of pixels (200x200). Try zooming in on an interesting-looking
region of the intensity map using a zoom box. Hold the shift key down and drag
the mouse to create the zoom box. Then click inside the zoom box to expand the display.
Even though you still have only 200x200 pixels, the display will look smoother because
all these pixels are focused on a smaller region of the more quickly changing z data.
You can also zoom in by right-clicking on the "view all" button in the lower right
corner. Then left-click on the view all button to expand the limits back to their
original values to show the entire z data set.
- Also try opening a zoom box in the 2D plot (left). You can do this as before
(shift key and mouse drag) or try the "double click and drag" mouse technique
which avoids having to use the keyboard. You may be surprised to see that the
intensity map zooms to show the region inside the zoom box of the 2D plot even
as you are dragging the edge of the zoom box. If you then click inside the zoom box
the 2D plot will also expand to show just the region inside the zoom box ... but let's
not do this just yet. First, try moving the zoom box around. Do this by clicking the
mouse near the mid-point of any edge, and dragging the zoom box around while holding the
mouse button down. Also, note that if you drag one of the corners instead of a midpoint
then the zoom box changes its size instead of its position. In both cases, the intensity
map continues to update so that it shows only the zoom box region. These mouse motions
are further described in the heading
Adjusting the expansion box in the Zooming and panning section.
- Try sliding the resolution slider (just to the left of the color bar) all the way to
the top of the slider. This will select a resolution of 800x800 (16 times as many
pixels as before) so the display will look much smoother, but the drawback is that the
update rate will be much slower. Try moving the slider all the way to the bottom
(50x50 pixels). Now the intensity map will look very blocky, and the update rate will
be very fast. Note that when you click inside the intensity map, the cursor will
center itself on one of the blocks even if you click near the edge of one of the
blocks. This makes it easier to interpret the Z value cursor readout (shown below
the intensity map. Also, note the x and y cursor readouts are updated as you would
expect every time you click on the image. Reset the resolution slider to 200 before
continuing. The resolution slider works differently when 2D convolution is being used
(i.e. when one of the first 5 choices in the kernel popup menu is selected.) In that
case, the value from the slider is divided by 3 to determine the resolution. So for
example, if the slider is set to 800, the resolution of the image is actually 267 by 267.
This is done because high resolutions make it difficult to see what is happening with
the 2D convolutions.
- Both plots are set in motion by clicking on the "Run" button. What
happens is that a random selection of the 10 sliders above the 2D plot is selected to
start moving. (The remaining sliders that are held fixed are made invisible so you can
easily see what is changing). As the sliders are moving up and down, both the 2D and 3D
plots are continuously updated to reflect the new information in the sliders. As this is
happening you will see the small (blue) frame counter below the Run/Stop button counting
down from 100 to zero. When zero is reached, a new random selection is made from the set
of 10 sliders and the frame counter begins down counting anew from 100. While all this is
happening, you may change the speed slider to adjust the motion rates and you also may
adjust any of the other controls as well and observe the effects of these changes immediately.
If you find that 100 frame count is too long or short for your taste, simply click on the yellow "100" and
you will be presented with a popup menu allowing you to vary this frame count from as small
as five to as large as 1000.
- Note that if you call pltmap with any argument, pltmap will
start as if the run button has already been pressed. The funcStart
function is used to initiate the run which allows pltmap to return control to the
command prompt even while continuing to update the moving intensity maps.
|